package com.schoolMall.controller.shopAdmin;

import com.schoolMall.domain.ProductCategory;
import com.schoolMall.domain.Shop;
import com.schoolMall.service.ProductCategoryService;
import com.schoolMall.service.ProductService;
import com.schoolMall.service.ShopService;
import com.schoolMall.utils.HttpServletRequestUtil;
import com.schoolMall.utils.ModelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author:zyh
 * @Time:2021-09-03-15:20
 * @email:1269231889@qq.com
 */
@Controller
@RequestMapping("/schoolMall/detail")
public class ShopDetailController {
    @Autowired
    private ShopService shopService;
    @Autowired
    private ProductCategoryService productCategoryService;
    @Autowired
    private ProductService productService;

    @ResponseBody
    @GetMapping("/getShopDetail")
    public Map<String, Object> getShopDetail(HttpServletRequest request) {
        Map<String, Object> model = new HashMap<>();
        long shopId = HttpServletRequestUtil.getLong(request, "shopId");
        try {
            if (shopId < 1) {
                return ModelUtil.fail("商铺Id问题");
            }
            Shop shop = shopService.queryShopById(shopId);
            model.put("shop", shop);
            List<ProductCategory> productCategories = productCategoryService.queryProductCategory(shopId);
            model.put("productCategoryList", productCategories);
            model.put("success", true);
        } catch (Exception e) {
            return ModelUtil.fail(e.getMessage());
        }
        return model;
    }
}
